package com.android.minetopin.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.minetopin.R;
import com.android.minetopin.activity.mine.TransparentActivity;
import com.android.minetopin.adapt.MainlistAdapt;
import com.android.minetopin.app.BaseActivity;
import com.android.minetopin.enums.EJumpStatus;
import com.android.minetopin.model.group.AdPictureData;
import com.android.minetopin.model.group.AdPictureDataCallback;
import com.android.minetopin.model.group.MainList;
import com.android.minetopin.model.group.MainListCallback;
import com.android.minetopin.model.group.SortHeadThumbData;
import com.android.minetopin.model.group.SortHeadThumbDataCallback;
import com.android.minetopin.model.group.ThematicAGoodsData;
import com.android.minetopin.model.group.ThematicAGoodsDataCallback;
import com.android.minetopin.utils.ConstantsUrl;
import com.android.minetopin.utils.HttpUtils;
import com.android.minetopin.utils.JumpUtils;
import com.android.minetopin.utils.MyLog;
import com.android.minetopin.utils.ObjectUtils;
import com.android.minetopin.utils.ReleaseManager;
import com.android.minetopin.view.group.VRefreshLayout;
import com.android.minetopin.view.recycleview.CustomLoadMoreView;
import com.android.minetopin.view.recycleview.CustomRecycleView;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

public class MainRecommendType extends BaseActivity implements BaseQuickAdapter.RequestLoadMoreListener {

    @BindView(R.id.listView)
    CustomRecycleView mRecyclerView;
    @BindView(R.id.swipe_refresh_layout)
    VRefreshLayout mRefreshLayout;
    @BindView(R.id.progress)
    RelativeLayout progress;
    @BindView(R.id.no_data_tv)
    TextView noDataTv;
    @BindView(R.id.no_data)
    RelativeLayout noData;
    @BindView(R.id.click_resetnetwork_msg)
    TextView clickResetnetworkMsg;
    @BindView(R.id.click_resetnetwork_refresh)
    TextView clickResetnetworkRefresh;
    @BindView(R.id.main_top_share)
    ImageView main_top_share;
    @BindView(R.id.click_resetnetwork)
    LinearLayout clickResetnetwork;
    private boolean networkConnected;
    private MainlistAdapt adapter;
    private AdaptList ta_adapter;
    private int page = 1;
    private MainRecommendType mcontext;
    private String type;
    private String sorttitle;
    private LinearLayoutManager mLayoutManager;
    private StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
    private GridLayoutManager mGridLayoutManager;
    private View head;
    private String shareurl;
    private String sharethumb;
    private String sharecontent="";

    String return_type=null;//跳转的参数
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_recycle_refresh);
        ButterKnife.bind(this);
        mcontext = MainRecommendType.this;
        sorttitle = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_SORT_SHOW_TITLE);
        type = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_SORT_SHOW_LINK);
        return_type = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.return_type);
        main_top_share.setVisibility(View.VISIBLE);
        initTitle(0, sorttitle);
        switch (sorttitle) {
            case "免费试用":
            case "试用团":
                type = "2";
                break;
            case "每日抽奖":
            case "抽奖团":
                type = "5";
                break;
            case "邻居团":
            case "AA团":
                type = "6";
                break;
            default:
                type = "1";
                break;
        }
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        initUI();
        if (networkConnected) {
            GetTypeData(true);
        } else {

            ObjectUtils.GetDataNet(clickResetnetwork, progress, 4);
        }


    }

    private void initRecycle() {

        if(return_type!=null) {
            if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumFreePostage.getRegmatch())) {
                ta_adapter = new AdaptList(mcontext,ta_listdata,"");
                ta_adapter.setLoadMoreView(new CustomLoadMoreView());
                ta_adapter.setOnLoadMoreListener(this,mRecyclerView);
                ta_adapter.addHeaderView(head);
                mLayoutManager = new LinearLayoutManager(mcontext);
                mGridLayoutManager = new GridLayoutManager(mcontext, 2);
                mRecyclerView.setLayoutManager(mLayoutManager);
                findViewById(R.id.top).setVisibility(View.GONE);
                //  mRecyclerView.GetToTop((ImageView) findViewById(R.id.top), 0);
                ta_adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(BaseQuickAdapter adapter1, View view, int position) {
                        ObjectUtils.ToDetailActivity(mcontext, 1, ta_adapter.getItem(position).getId(), "");
                    }
                });
                return;
            }
        }


        switch (sorttitle) {
            case "美食汇":
            case "9.9元包邮":
                ta_adapter = new AdaptList(mcontext,ta_listdata,"");
                ta_adapter.setLoadMoreView(new CustomLoadMoreView());
                ta_adapter.setOnLoadMoreListener(this,mRecyclerView);
                ta_adapter.addHeaderView(head);
                mLayoutManager = new LinearLayoutManager(mcontext);
                mGridLayoutManager = new GridLayoutManager(mcontext, 2);
                mRecyclerView.setLayoutManager(mGridLayoutManager);
                findViewById(R.id.top).setVisibility(View.GONE);
             //  mRecyclerView.GetToTop((ImageView) findViewById(R.id.top), 0);
                ta_adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(BaseQuickAdapter adapter1, View view, int position) {
                                ObjectUtils.ToDetailActivity(mcontext, 1, ta_adapter.getItem(position).getId(), "");
                        }
                });
                break;
            default:
                adapter = new MainlistAdapt(mcontext, null, type);
                //  adapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
                adapter.setLoadMoreView(new CustomLoadMoreView());
                adapter.setOnLoadMoreListener(this, mRecyclerView);
            mLayoutManager = new LinearLayoutManager(mcontext);
            mRecyclerView.setLayoutManager(mLayoutManager);
            mRecyclerView.setAdapter(adapter);
        mRecyclerView.GetToTop((ImageView) findViewById(R.id.top), 0);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter1, View view, int position) {


                if (return_type != null) {
                    if (JumpUtils.IsRegmatch(return_type, EJumpStatus.ELottery.getRegmatch())) {
                        int showId = getShowId(position);
                        ObjectUtils.ToDetailActivity(mcontext, showId, adapter.getItem(position).getId(), "");
                        return;
                    } else if (JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumFreeTest.getRegmatch())) {
                        int showId = getShowId(position);
                        ObjectUtils.ToDetailActivity(mcontext, showId, adapter.getItem(position).getId(), "");
                        return;
                    }
                }


                switch (sorttitle) {
                    case "每日抽奖":
                    case "抽奖团":
                    case "免费试用":
                    case "试用团":
                        int showId = getShowId(position);
                        ObjectUtils.ToDetailActivity(mcontext, showId, adapter.getItem(position).getId(), "");
                        break;
                    default:
                        ObjectUtils.ToDetailActivity(mcontext, 1, adapter.getItem(position).getId(), "");
                        break;
                }

            }
        });
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public boolean onItemChildClick(BaseQuickAdapter adapter1, View view, int position) {
                switch (view.getId()) {
                    case R.id.main_list_item_go_kai:
                    case R.id.ll_free:
                        ObjectUtils.ToDetailActivity(mcontext, 1, adapter.getItem(position).getId(), "");
                        break;
                    case R.id.ll_start_soon:
                        ObjectUtils.ToDetailActivity(mcontext, 3, adapter.getItem(position).getId(), "");
                        break;
                    case R.id.ll_result:
                        Intent intent = new Intent(mcontext, BaseObject.class);
                        if(type.equals("2")){
                            intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, "试用结果");
                        }else if(type.equals("5")){
                            intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_TITLE, "中奖名单");
                        }
                        intent.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_NEED_ID, adapter.getItem(position).getId());
                        startActivity(intent);
                        break;

                }
                return false;
            }
        });
                break;
        }
    }

    private int getShowId(int position) {
        int end = Integer.parseInt(adapter.getItem(position).getEnd_time());
        int start = Integer.parseInt(adapter.getItem(position).getStart_time());
        int run = adapter.getItem(position).getRun_time();
        if (run > end && run > start) {
            return 5;
        } else if (run > start && run < end) {
            return 1;
        } else if (run < start) {
            return 3;
        }else {
            return 1;
        }
    }

    private void initUI() {
        head = getLayoutInflater().inflate(R.layout.item_list_sort_dapai, null, false);
        head.findViewById(R.id.ll_msg).setVisibility(View.GONE);
        initRecycle();

        if(return_type!=null) {
            if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumFreeTest.getRegmatch())) {
                adapter.addHeaderView(head);
                Refresh();
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumNew.getRegmatch())) {
                adapter.addHeaderView(head);
                Refresh();
                return;
            }
        }

        switch (sorttitle) {
            case "品牌折扣":

                break;
            case "免费试用":
                adapter.addHeaderView(head);
                break;

            case "抽奖团":
                adapter.addHeaderView(head);
                break;
            default:
                break;
        }

        Refresh();
    }


    private void Refresh() {
        if (mRefreshLayout != null) {
            mRefreshLayout.setBackgroundColor(Color.TRANSPARENT);
            mRefreshLayout.setAutoRefreshDuration(400);
            mRefreshLayout.setRatioOfHeaderHeightToReach(1.5f);
            mRefreshLayout.addOnRefreshListener(new VRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    networkConnected = ObjectUtils.isNetworkConnected(mcontext);
                    if (networkConnected) {
                        mRefreshLayout.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                page=1;
                                GetTypeData(true);
                                mRefreshLayout.refreshComplete();
                            }
                        }, 1000);
                    } else {
                        ObjectUtils.toast(mcontext, "网络连接出现异常");
                    }
                }
            });
        }

    }

    @OnClick({R.id.click_resetnetwork_refresh,R.id.main_top_share})
    public void onClick(View view) {
        switch  (view.getId()) {
            case R.id.click_resetnetwork_refresh:
            ObjectUtils.GetDataNet(clickResetnetwork, progress, 3);
            page = 1;
            GetTypeData(true);
                break;
            case R.id.main_top_share:


                Intent share = new Intent(mcontext, TransparentActivity.class);
                share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_TYPE, 1);
                share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_CONTENT, "这么划算真的不来抢吗");



                if(return_type!=null) {
                    if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumPromote.getRegmatch())) {
                        shareurl = ConstantsUrl.domain +"goods/index/?typeid=8";
                        share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_TITLE, getString(R.string.app_name)+"~" + sharecontent);
                        share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_IMAGEURL, sharethumb);
                        share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_LINK, shareurl);
                        mcontext.startActivity(share);
                        return;
                    }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.ELottery.getRegmatch())) {
                        return;
                    }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumFreeTest.getRegmatch())) {
                        return;
                    }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumNew.getRegmatch())) {
                        return;
                    }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumNeighbor.getRegmatch())) {
                        return;
                    }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumLadder.getRegmatch())) {
                        return;
                    }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumSelf.getRegmatch())) {
                        return;
                    }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumFreePostage.getRegmatch())) {
                        return;
                    }
                }

                switch (sorttitle) {
                    case "推广团":
                        shareurl = ConstantsUrl.domain +"goods/index/?typeid=8";
                        share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_TITLE, getString(R.string.app_name)+"~" + sharecontent);
                        share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_IMAGEURL, sharethumb);
                        share.putExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_LINK, shareurl);
                        break;
                    case "免费试用":

                        break;
                    case "品牌折扣":

                        break;
                    case "9.9元包邮":

                        break;
                    case "每日抽奖":
                        break;
                    case "邻居团":

                        break;
                }
                mcontext.startActivity(share);
                break;
        }
    }

    @Override
    public void onLoadMoreRequested() {
        page = page + 1;
        GetTypeData(false);
    }

    private void GetTypeData(boolean isloadhead) {


        ReleaseManager.printLog("GetTypeData","return_type "+return_type);
        if(return_type!=null) {
            if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumPromote.getRegmatch())) {
                GetListData(page, "&typeid=8");
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.ELottery.getRegmatch())) {
                if (isloadhead) {

                    GetDataBanner("6");
                }
                GetListData(page, "&typeid=6&order=lottery");
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumFreeTest.getRegmatch())) {
                if (isloadhead) {

                    GetDataBanner("5");
                }
                GetListData(page, "&typeid=5&order=lottery");
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumNew.getRegmatch())) {

                ReleaseManager.printLog("GetListData",return_type);
                if (isloadhead) {

                    GetDataBanner("7");
                }
                GetListData(page, "&typeid=2&order=lottery");
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumNeighbor.getRegmatch())) {
                GetListData(page, "&typeid=7");
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumLadder.getRegmatch())) {
                GetListData(page, "&typeid=10");
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumSelf.getRegmatch())) {
                GetListData(page, "&typeid=9");
                return;
            }else  if(JumpUtils.IsRegmatch(return_type, EJumpStatus.EnumFreePostage.getRegmatch())) {
                GetTaListData(page);
                return;
            }
        }

        switch (sorttitle) {
            case "推广团":
                //推广
                GetListData(page, "&typeid=8");
                break;
            case "免费试用":
                if (isloadhead) {

                    GetDataBanner("5");
                }
                GetListData(page, "&typeid=5&order=lottery");
                break;

            case "9.9元包邮":
                GetTaListData("3",page);
                break;
            case "每日抽奖":
                if (isloadhead) {

                    GetDataBanner("6");
                }
                GetListData(page, "&typeid=6&order=lottery");
                break;
            case "邻居团":
                GetListData(page, "&typeid=7");
                break;

            case "9":
                //自选
                GetListData(page, "&typeid=9");
                break;
            case "10":
                //阶梯
                GetListData(page, "&typeid=10");
                break;
            case "美食汇":
                GetTaListData("7",page);
                break;
        }

    }

    /**
     * 专题活动 new
     */
    private void GetTaListData(final int page) {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address = ConstantsUrl.domain + ConstantsUrl.THEMATICGOODSLIST;
        HashMap<String,String> map = new HashMap<>();
        map.put("id", "3");
        map.put("page",page+"");
        if (networkConnected) {
            HttpUtils.get(address, map, new ThematicAGoodsDataCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
                }

                @Override
                public void onResponse(ThematicAGoodsData response, int id) {

                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
                    if (response.getCode() == 0) {
                        if (response.getData().getList() == null && page == 1) {
                            noData.setVisibility(View.VISIBLE);
                            return;
                        }

                        if (response.getData().getList() != null && response.getData().getList().size() > 0) {
                            if (page == 1) {
                                ta_listdata.clear();
                                ta_listdata.addAll(response.getData().getList());
                                ta_adapter.setNewData(ta_listdata);
                                ObjectUtils.photo2(mcontext, response.getData().getTopic().getThumbs().get(0), (ImageView) head.findViewById(R.id.item_list_sort_dapai_img));
                                mRecyclerView.setAdapter(ta_adapter);
                            } else {
                                ta_listdata.addAll(response.getData().getList());
                                ta_adapter.addData(ta_listdata);
                                ta_adapter.loadMoreComplete();
                            }
                        } else {
                            ta_adapter.loadMoreEnd();
                        }
                    } else {
                        noData.setVisibility(View.VISIBLE);
                        noDataTv.setVisibility(View.VISIBLE);
                        noDataTv.setText(response.getMsg());
                    }
                }
            });
        } else {
            if (page == 1) {
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
            }
            ObjectUtils.toast(mcontext, "网络连接出现异常");
        }
    }

    private ArrayList<ThematicAGoodsData.DataBean.ListDataBean> ta_listdata = new ArrayList<>();
    /**
     * 专题活动
     */
    private void GetTaListData(String id,final int page) {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address = ConstantsUrl.domain + ConstantsUrl.THEMATICGOODSLIST;
        HashMap<String,String> map = new HashMap<>();
        map.put("id", id);
        map.put("page",page+"");
        if (networkConnected) {
            HttpUtils.get(address, map, new ThematicAGoodsDataCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
                }

                @Override
                public void onResponse(ThematicAGoodsData response, int id) {

                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
                    if (response.getCode() == 0) {
                        if (response.getData().getList() == null && page == 1) {
                            noData.setVisibility(View.VISIBLE);
                            return;
                        }

                        if (response.getData().getList() != null && response.getData().getList().size() > 0) {
                            if (page == 1) {
                                ta_listdata.clear();
                                ta_listdata.addAll(response.getData().getList());
                                ta_adapter.setNewData(ta_listdata);
                                ThematicAGoodsData.DataBean.TopicDateBean topic = response.getData().getTopic();
                                if (topic != null && topic.getThumbs() != null && topic.getThumbs().size() > 0) {
                                    ObjectUtils.photo2(mcontext, response.getData().getTopic().getThumbs().get(0), (ImageView) head.findViewById(R.id.item_list_sort_dapai_img));
                                } else {
                                    ta_adapter.removeHeaderView(head);
                                }
                                mRecyclerView.setAdapter(ta_adapter);
                            } else {
                                ta_listdata.addAll(response.getData().getList());
                                ta_adapter.addData(ta_listdata);
                                ta_adapter.loadMoreComplete();
                            }
                        } else {
                            ta_adapter.loadMoreEnd();
                        }
                    } else {
                        noData.setVisibility(View.VISIBLE);
                        noDataTv.setVisibility(View.VISIBLE);
                        noDataTv.setText(response.getMsg());
                    }
                }
            });
        } else {
            if (page == 1) {
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
            }
            ObjectUtils.toast(mcontext, "网络连接出现异常");
        }
    }


    public class AdaptList extends BaseMultiItemQuickAdapter<ThematicAGoodsData.DataBean.ListDataBean, BaseViewHolder> {

        public AdaptList(Context context, ArrayList<ThematicAGoodsData.DataBean.ListDataBean> data, String type){
            super(data);
            addItemType(ConstantsUrl.THEMATICGOODSLISTItemTYPE, R.layout.item_grid_detail_like);
        }

        @Override
        protected void convert(BaseViewHolder holder, ThematicAGoodsData.DataBean.ListDataBean mainlistdata) {
            switch (holder.getItemViewType()) {
                case ConstantsUrl.THEMATICGOODSLISTItemTYPE:
                    ((TextView) holder.getView(R.id.item_grid_detail_like_number_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                    ObjectUtils.photo2(mcontext, mainlistdata.getImg_src(),(ImageView) holder.getView(R.id.item_grid_detail_like_img));
                    holder.setText(R.id.item_grid_detail_like_title, mainlistdata.getName());
                    holder.setText(R.id.item_grid_detail_like_number_after, mainlistdata.getTeam_price());
                    holder.setText(R.id.item_grid_detail_like_number_before,mainlistdata.getPrice());
                    holder.setText(R.id.item_grid_detail_like_tuanshu, "已团" + mainlistdata.getSell_num() + "件");
                    break;
            }
        }
    }
    /**
     * 轮播图
     */
    private void GetDataBanner(String typeid) {

        String address = ConstantsUrl.domain + ConstantsUrl.ADVERTISEPICTURE;
        MyLog.e("地址", address);
        HashMap<String, String> map = new HashMap<>();
        map.put("typeid",typeid);
        HttpUtils.get(address, map, new  AdPictureDataCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
            }

            @Override
            public void onResponse(AdPictureData response, int id) {
                if (response.getData() != null && response.getData().getAd() != null && response.getData().getAd().size() > 0) {
                    ObjectUtils.photo2(mcontext, response.getData().getAd().get(0).getPath(), (ImageView) head.findViewById(R.id.item_list_sort_dapai_img));
                  sharethumb=response.getData().getAd().get(0).getPath();
                }


            }
        });

    }

    //获取主页列表数据
    private void GetListData(final int page, String linktype) {
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address = ConstantsUrl.domain + ConstantsUrl.MAIN_LISTDATA + "?page=" + page + linktype;

        MyLog.e("地址", address);
        if (networkConnected) {
            HttpUtils.get(address, null, new MainListCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
                }

                @Override
                public void onResponse(MainList response, int id) {
                    ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);

                    if (response.getCode() == 0) {

                        List<MainList.MainListdata.Mainlistdata> list = response.getData().getList();
                        if (list == null && page == 1) {
                            noData.setVisibility(View.VISIBLE);
                            return;
                        }
                        ArrayList<MainList.MainListdata.Mainlistdata> listdata = new ArrayList<>();

                        if (list != null && list.size() > 0) {

                            if ( sorttitle.equals("抽奖团")) {
                                for (int i = 0; i < list.size(); i++) {
                                    listdata.add(new MainList.MainListdata.Mainlistdata(0, list.get(i).getId()
                                            , list.get(i).getTypeid(), list.get(i).getName(), list.get(i).getPrice(), list.get(i).getTeam_price(), list.get(i).getDiscount_price()
                                            , list.get(i).getThumb(), list.get(i).getTeam_num(), list.get(i).getTeam_people_num(), list.get(i).getLuck_num(), list.get(i).getEnd_time()
                                            , list.get(i).getStart_time(), list.get(i).getRun_time()));
                                }
                                mRecyclerView.setLayoutManager(mLayoutManager);
                                mRecyclerView.setAdapter(adapter);
                                if (page == 1) {
                                    adapter.setNewData(listdata);
                                } else {
                                    adapter.addData(listdata);
                                    adapter.loadMoreComplete();
                                }
                            } else {
                                for (int i = 0; i < list.size(); i++) {
                                    listdata.add(new MainList.MainListdata.Mainlistdata(response.getData().getList_type(), list.get(i).getId()
                                            , list.get(i).getTypeid(), list.get(i).getName(), list.get(i).getPrice(), list.get(i).getTeam_price(), list.get(i).getDiscount_price()
                                            , list.get(i).getThumb(), list.get(i).getTeam_num(), list.get(i).getTeam_people_num(), list.get(i).getLuck_num(), list.get(i).getEnd_time()
                                            , list.get(i).getStart_time(), list.get(i).getRun_time()));
                                }
                                if (page == 1) {
                                    adapter.setNewData(listdata);

                                    if (response.getData().getList_type() == 0) {
                                        mRecyclerView.setLayoutManager(mLayoutManager);
                                        mRecyclerView.setAdapter(adapter);
                                    } else {
                                        mRecyclerView.setLayoutManager(mGridLayoutManager);
                                        mRecyclerView.setAdapter(adapter);
                                    }

                                } else {
                                    adapter.addData(listdata);
                                    adapter.loadMoreComplete();
                                }
                                sharethumb = list.get(0).getThumb();
                            }
                        } else {
                            adapter.loadMoreEnd();
                        }
                    } else {
                        noData.setVisibility(View.VISIBLE);
                        noDataTv.setVisibility(View.VISIBLE);
                        noDataTv.setText(response.getMsg());
                    }
                }
            });
        } else {
            if (page == 1) {
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 2);
            }
            ObjectUtils.toast(mcontext, "网络连接出现异常");
            adapter.loadMoreFail();
        }
    }

    private void GetDataHeadImage(String imagetype) {
        String address = ConstantsUrl.domain + imagetype;
        HttpUtils.get(address, null, new SortHeadThumbDataCallback() {

            @Override
            public void onError(Call call, Exception e, int id) {
            }

            @Override
            public void onResponse(SortHeadThumbData response, int id) {
                if (response.getData() != null) {
                    ObjectUtils.photo2(mcontext, response.getData(), (ImageView) head.findViewById(R.id.item_list_sort_dapai_img));
                    adapter.notifyDataSetChanged();
                }

            }

        });

    }


}
